<style>
    .btn {
        width: 10px;
        height: 20px;
        background: #52b2f3;
        position: fixed;
        left: 10px;
        top: 0;
        opacity: 0.2;
        cursor: pointer;
        z-index: 999;
    }

    .btn:hover {
        opacity: 0.6;
    }

    .orange {
        background: #f57139;
        left: 30px;
    }

    .red {
        background: #f00;
        left: 50px;
    }
    .green {
        background: #76edcd;
        left: 70px;
    }
</style>
<div class="btn blue cf"></div>
<div class="btn orange openCmsDev"></div>
<div class="btn red loadKafMiniApp"></div>
<div class="btn green copyId"></div>

<script>
    bindClick('.cf', cf);
    bindClick('.openCmsDev', openCmsDev);
    bindClick('.loadKafMiniApp', loadKafMiniApp);
    bindClick('.copyId', copyId);

    function loadKafMiniApp() {
        __miniappUtils.enableDev();
        __miniappUtils.loadApp("3001", "http://localhost:3001/manifest.json");
        __miniappUtils.loadApp("3000", "http://localhost:3000/manifest.json");
        __miniappUtils.loadApp("8009", "http://127.0.0.1:8009/manifest.json");
        __miniappUtils.loadApp("8080", "http://127.0.0.1:8080/manifest.json");
        __miniappUtils.loadApp("8081", "http://127.0.0.1:8081/manifest.json");
        __miniappUtils.loadApp("8082", "http://127.0.0.1:8082/manifest.json");
        __miniappUtils.loadApp("8083", "http://127.0.0.1:8083/manifest.json");
        __miniappUtils.loadApp("5173", "http://127.0.0.1:5173/manifest.json");
        __miniappUtils.loadApp("8001", "http://127.0.0.1:8001/manifest.json");
        __miniappUtils.loadApp("解单助手BOM", "https://kuu.findcn.cn/kuuReact2/manifest.json")
        __miniappUtils.loadApp("miniapp-custom-sdk-test", "http://localhost:6888/pub/tool/custom/miniapp-custom-sdk-test");
    }

    function getSelect() {
        return window.__custom__.framework().axr.axrs.select.selected[0];
    }

    function openCmsDev() {
        window.open('https://sit.kujiale.com/pub/saas/customized-cms/miniapp?enableMiniappDev=true&launchMiniapp=8000');
    }

    function cf() {
        window.open('https://cf.qunhequnhe.com/spaces/viewspace.action?key=~xianyang');
    }

    const openCustomTool = () => {
        const key = '__defaultCustomID__';
        const value = '_:showInfo';
        const preValue = window.localStorage.getItem(key);
        if (preValue !== value) {
            window.localStorage.setItem(key, value);
            if (confirm("检测到未开启定制调试工具，已自动设置成功，是否刷新页面生效？")) {
                window.location.reload();
            }
            return false;
        }
        return true;
    };

    function copyId() {
        openCustomTool();
        const id = __CUSTOM_GUIDE_INFO().cFrameApp().framework.axr.select.select.state.selectedObjects[0]?.id;
        // 创建一个隐藏的textarea元素
        const textarea = document.createElement("textarea");
        textarea.value = id; // 设置内容为需要复制的字符串
        document.body.appendChild(textarea); // 将textarea添加到文档中

        // 选择内容并执行复制
        textarea.select();
        textarea.setSelectionRange(0, id.length); // 兼容性处理
        document.execCommand("copy"); // 执行复制命令

        // 移除textarea元素
        document.body.removeChild(textarea);
    }

    function bindClick(st, cb) {
        document.querySelector(st).addEventListener('click', cb);
    }
</script>
